package com.xuliugen.security.web.validator;

import com.xuliugen.security.web.service.HelloService;
import org.springframework.beans.factory.annotation.Autowired;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;

/**
 * Created by xuliugen on 2017/11/5.
 */
public class MyConstraintValidator implements ConstraintValidator<MyConstraint, Object> {

    private final HelloService helloService;

    @Autowired
    public MyConstraintValidator(HelloService helloService) {
        this.helloService = helloService;
    }

    @Override
    public void initialize(MyConstraint constraintAnnotation) {
        System.out.println("validator init");
    }

    @Override
    public boolean isValid(Object value, ConstraintValidatorContext context) {
        helloService.sayHello("xuliugen");
        System.out.println(value);
        return false;
    }

}
